package dproxy.server.net.backoff;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Generates a linear backoff: timeout is divided in equal times.
 */
class LinearIntervalGenerator extends IntervalGenerator {

    /**
     * @see IntervalGenerator#getIntervals(int, int)
     */
    @Override
    public Collection<Integer> getIntervals(int readTimeout, int readRetestTimes) {
        Collection<Integer> times = new ArrayList<Integer>(readRetestTimes);
        double dInterval = (double) readTimeout / readRetestTimes;
        int interval = (int) dInterval;
        
        for (int i = 0; i < readRetestTimes; i++) {
            times.add(interval);
        }
        
        return times;
    }

}
